﻿#include "mymainwindow.h"
#include <QtGui/QApplication>
#include <QAction>
#include <QTreeWidget>
#include <QAction>
#include <QMenu>
#include <QtGui/QMdiArea>
#include <QMdiSubWindow>
#include <QSignalMapper>
#include <QTextEdit>
#include <QIcon>
#include <QMenuBar>
#include <QToolBar>
#include <QSize>
#include <QStatusBar>
#include <QDockWidget>
#include <QListWidget>
#include <QMenu>
#include <QPoint>
#include <QList>
#include "mytablewidget.h"
#include "mytreewidget.h"
#include <QDateTime>
#include <QScrollBar>
#include <QCursor>
#include <QContextMenuEvent>
#include <QFileDialog>
#include <QMessageBox>
#include <QPalette>
#include <QProgressDialog>
#include "transdlg.h"
#include "InsertDevModeDlg.h"
#include "DeviceDlg.h"
#include "ExpEditDlg.h"
//#include "DeviceParamDlg.h"
#include "ExportParamDbdlg.h"
#include "ExportXmlDlg.h"
#include "LogicNodeDlg.h"
#include "GenerateTotalSort.h"


void MyMainWindow::InitPoint()
{
	//	m_pMdiArea = NULL;
	m_pTreeWdgt = NULL;
	m_pSysMenu = NULL;
	m_pOperMenu = NULL;
	m_pViewMenu = NULL;
	m_pAboutMenu = NULL;
	m_pOperTlBar = NULL;
	//	m_pUserAct = NULL;
	m_pfreshTreeAct =NULL;
	//	m_pDSNMgrAct = NULL;
	m_pExitAct = NULL;
	m_pAddAct = NULL;
	m_pDelAct = NULL;
	m_pSetColAct = NULL;
	m_pSaveModelAct = NULL;
	m_pSaveModelFileAct = NULL;
	m_pSaveDataAct = NULL;
	//	m_pOnLineUpdateAct = NULL;
	m_pRefreshAct = NULL;
	m_pTreeAct = NULL;
	m_pOperInfoAct = NULL;
	m_pPropertyAct = NULL;
	m_pAboutAct = NULL;
	m_pLeftTreeDock = NULL;
	m_pBottomTextDock = NULL;
	m_pRightDock = NULL;
	//    m_pDbCfgView = NULL;
	m_PopMenu = NULL;
	//	m_pYcTableAct = NULL;
	//	m_pInputSCD = NULL;

	m_pPrePageAct = NULL;
	m_pNextPageAct= NULL;
	m_pHeadPageAct= NULL;
	m_pTailPageAct= NULL;
	m_pTree = NULL;
	m_pCentralTab =NULL;
	m_pLastSeltTreeItem = NULL;
}

MyMainWindow::MyMainWindow(QWidget *parent) :
    QMainWindow(parent)
{	
	int ret=InitApp();
	if (ret<=0)
	{
		QMessageBox::about(this,QString::fromLocal8Bit("初始化错误"),QString::fromLocal8Bit("初始化SQLite失败 错误码%1").arg(QString::number(ret)));
		exit(0);
	}

	InitPoint();

	createActions();
	createMenus();
	createToolBars();
	createStatusBar();
	setupPopMenuBar();
	createCentralWidget();
	createDockWindows();
	ConnectFunction();

	setWindowTitle(QString::fromLocal8Bit("NSA3100HF配网数据库组态"));
	setWindowIcon(QIcon(":Res/images/AdministrativeTools.png"));
}

MyMainWindow::~MyMainWindow()
{
	int ret=FinitApp();
}

void MyMainWindow::closeEvent(QCloseEvent *event)
{
	if (!event)
	{
		return ;
	}
	event->accept();
}

void MyMainWindow::createActions()
{
	m_pfreshTreeAct = new QAction(QString::fromLocal8Bit("刷新树"), this);
	m_pfreshTreeAct->setStatusTip(QString::fromLocal8Bit("树形结构刷新"));

	m_pExitAct = new QAction(QString::fromLocal8Bit("退出(&Q)"), this);
	m_pExitAct->setStatusTip(QString::fromLocal8Bit("退出数据库组态工具。"));
	m_pAddAct = new QAction(QIcon(":Res/images/add.png"), QString::fromLocal8Bit("添加(&N)"), this);
	m_pAddAct->setStatusTip(QString::fromLocal8Bit("添加一条新的记录。"));
	m_pAddAct->setEnabled(false);

	m_pSaveModelAct = new QAction(QIcon(":Res/images/copy.png"), QString::fromLocal8Bit("保存模板"), this);
	m_pSaveModelAct->setStatusTip(QString::fromLocal8Bit("将选中的设备保存为模板"));
	m_pSaveModelAct->setEnabled(false);

	m_pSaveModelFileAct = new QAction(QIcon(":Res/images/copy.png"), QString::fromLocal8Bit("保存模板文件"), this);
	m_pSaveModelFileAct->setStatusTip(QString::fromLocal8Bit("将选中的设备模板保存为文件"));
	m_pSaveModelFileAct->setEnabled(false);

	m_pDelAct = new QAction(QIcon(":Res/images/deletemenu.png"), QString::fromLocal8Bit("删除(&D)"), this);
	m_pDelAct->setStatusTip(QString::fromLocal8Bit("删除记录"));
	m_pDelAct->setEnabled(false);

	m_pSetColAct = new QAction(QIcon(":Res/images/setcolval.png"), QString::fromLocal8Bit("域值设置"), this);
	m_pSetColAct->setStatusTip(QString::fromLocal8Bit("设置选中列的值"));
	m_pSetColAct->setEnabled(false);

	m_pSaveDataAct = new QAction(QIcon(":Res/images/save.png"), QString::fromLocal8Bit("保存(&S)"), this);
	m_pSaveDataAct->setStatusTip(QString::fromLocal8Bit("保存记录数据"));
	m_pSaveDataAct->setEnabled(false);

	//m_pOnLineUpdateAct = new QAction(QIcon(":Res/images/updateline.png"), QString::fromLocal8Bit("在线修改(&P)"), this);
	//m_pOnLineUpdateAct->setStatusTip(QString::fromLocal8Bit("在线更新修改内容"));
	//m_pOnLineUpdateAct->setEnabled(false);

	// 	m_pYcTableAct = new QAction(QIcon(":Res/images/save.png"), QString::fromLocal8Bit("遥测历史表检查"), this);
	// 	m_pYcTableAct->setStatusTip(QString::fromLocal8Bit("遥测历史表检查"));
	// 	m_pYcTableAct->setEnabled(true);

	//m_pInputSCD = new QAction(QIcon(":Res/images/add.png"), QString::fromLocal8Bit("导入SCD文件"), this);
	//m_pInputSCD->setStatusTip(QString::fromLocal8Bit("导入SCD文件"));
	//m_pInputSCD->setEnabled(true);

	m_pTreeAct = new QAction(QString::fromLocal8Bit("导航信息"), this);
	m_pTreeAct->setStatusTip(QString::fromLocal8Bit("显示导航信息"));
	m_pTreeAct->setCheckable(true);
	m_pTreeAct->setChecked(true);

	m_pOperInfoAct = new QAction(QString::fromLocal8Bit("操作信息"), this);
	m_pOperInfoAct->setStatusTip(QString::fromLocal8Bit("显示操作信息和日记。"));
	m_pOperInfoAct->setCheckable(true);
	m_pOperInfoAct->setChecked(true);

	m_pPropertyAct = new QAction(QString::fromLocal8Bit("属性窗口"), this);
	m_pPropertyAct->setStatusTip(QString::fromLocal8Bit("显示当前选择记录的所有信息。"));
	m_pPropertyAct->setCheckable(true);
	m_pPropertyAct->setChecked(true);

	m_pRefreshAct = new QAction(QIcon(":Res/images/refresh.png"),QString::fromLocal8Bit("刷新(&F5)"), this);
	m_pRefreshAct->setStatusTip(QString::fromLocal8Bit("刷新当前表的记录数据。"));
	m_pRefreshAct->setEnabled(false);
	connect(m_pRefreshAct, SIGNAL(triggered()), this, SLOT(RefreshData()));

	m_pAboutAct = new QAction(QString::fromLocal8Bit("帮助(&H)"), this);
	m_pAboutAct->setStatusTip(QString::fromLocal8Bit("帮助"));

	m_pHeadPageAct = new QAction(QIcon(":Res/images/head.png"),QString::fromLocal8Bit(""), this);
	m_pHeadPageAct->setStatusTip(QString::fromLocal8Bit("显示第一页"));
	m_pHeadPageAct->setEnabled(false);

	m_pPrePageAct = new QAction(QIcon(":Res/images/prev.png"),QString::fromLocal8Bit(""), this);
	m_pPrePageAct->setStatusTip(QString::fromLocal8Bit("向前翻一页"));
	m_pPrePageAct->setEnabled(false);

	m_pNextPageAct = new QAction(QIcon(":Res/images/next.png"),QString::fromLocal8Bit(""), this);
	m_pNextPageAct->setStatusTip(QString::fromLocal8Bit("向后翻一页"));
	m_pNextPageAct->setEnabled(false);

	m_pTailPageAct = new QAction(QIcon(":Res/images/tail.png"),QString::fromLocal8Bit(""), this);
	m_pTailPageAct->setStatusTip(QString::fromLocal8Bit("显示最后一页"));
	m_pTailPageAct->setEnabled(false);

	//	m_pUserAct->setShortcut(QString::fromLocal8Bit("Ctrl+U"));
	m_pExitAct->setShortcut(QString::fromLocal8Bit("Ctrl+Q"));
	m_pAddAct->setShortcuts(QKeySequence::New);
	m_pDelAct->setShortcuts(QKeySequence::Delete);
	m_pSaveDataAct->setShortcuts(QKeySequence::Save);
	m_pRefreshAct->setShortcuts(QKeySequence::Refresh);
	m_pAboutAct->setShortcuts(QKeySequence::HelpContents);//快捷键

	//connect(m_pUserAct, SIGNAL(triggered()), this, SLOT(UserLogin()));
	//connect(m_pDSNMgrAct, SIGNAL(triggered()), this, SLOT(DSNMgr()));
	connect(m_pfreshTreeAct, SIGNAL(triggered()), this, SLOT(FreshTree()));


	connect(m_pExitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

	connect(m_pAddAct, SIGNAL(triggered()), this, SLOT(OnAddNewRecord()));   
	connect(m_pDelAct, SIGNAL(triggered()), this, SLOT(DeleteData()));

	//connect(m_pOnLineUpdateAct, SIGNAL(triggered()), this, SLOT(OnLineUpDate_slot()));
	connect(m_pTreeAct, SIGNAL(triggered()), this, SLOT(ShowTreeDock()));
	connect(m_pOperInfoAct, SIGNAL(triggered()), this, SLOT(ShowTextDock()));
	connect(m_pPropertyAct, SIGNAL(triggered()), this, SLOT(ShowPropertyDock()));
	connect(m_pRefreshAct, SIGNAL(triggered()), this, SLOT(RefreshData()));
	//connect(m_pAboutAct, SIGNAL(triggered()), g_pApp, SLOT(aboutQt()));
	//	connect(m_pYcTableAct, SIGNAL(triggered()), this, SLOT(CheckYcTable()));
	//connect(m_pInputSCD, SIGNAL(triggered()), this, SLOT(InputSCD_Slot()));

	connect(m_pHeadPageAct, SIGNAL(triggered()), this, SLOT(OnHeadPage()));
	connect(m_pPrePageAct, SIGNAL(triggered()), this, SLOT(OnPrevPage()));
	connect(m_pNextPageAct, SIGNAL(triggered()), this, SLOT(OnNextPage()));
	connect(m_pTailPageAct, SIGNAL(triggered()), this, SLOT(OnTailPage()));
	connect(&m_PageNoComBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnMoveToPage(int)));

}

void MyMainWindow::createMenus()
{
	m_pSysMenu = menuBar()->addMenu(QString::fromLocal8Bit("系统(&S)"));
	m_pOperMenu = menuBar()->addMenu(QString::fromLocal8Bit("编辑(&E)"));
	m_pViewMenu = menuBar()->addMenu(QString::fromLocal8Bit("窗口(&V)"));
	m_pAboutMenu = menuBar()->addMenu(QString::fromLocal8Bit("帮助(&H)"));

	m_pSysMenu->addAction(m_pfreshTreeAct);
	m_pSysMenu->addAction(m_pExitAct);

	m_pOperMenu->addAction(m_pAddAct);
	m_pOperMenu->addAction(m_pSetColAct);
	m_pOperMenu->addAction(m_pDelAct);
	m_pOperMenu->addSeparator();
	m_pOperMenu->addAction(m_pSaveDataAct);
	m_pOperMenu->addAction(m_pRefreshAct);
	m_pOperMenu->addSeparator();
	m_pOperMenu->addAction(m_pSaveModelAct);
	m_pOperMenu->addAction(m_pSaveModelFileAct);

	m_pViewMenu->addAction(m_pTreeAct);
	m_pViewMenu->addAction(m_pOperInfoAct);
	m_pViewMenu->addAction(m_pPropertyAct);
	
	m_pAboutMenu->addAction(m_pAboutAct);
	//  menuBar()->setFixedHeight(30);

}

void MyMainWindow::createToolBars()
{
	m_pOperTlBar = addToolBar(QString::fromLocal8Bit("Operate"));
	m_pOperTlBar->addAction(m_pAddAct);
	m_pOperTlBar->addSeparator();
	m_pOperTlBar->addAction(m_pSetColAct);
	m_pOperTlBar->addSeparator();
	m_pOperTlBar->addAction(m_pSaveModelAct);
	m_pOperTlBar->addAction(m_pSaveModelFileAct);
	m_pOperTlBar->addSeparator();
	m_pOperTlBar->addAction(m_pDelAct);
	m_pOperTlBar->addSeparator();
	m_pOperTlBar->addAction(m_pSaveDataAct);
	m_pOperTlBar->addSeparator();
//	m_pOperTlBar->addAction(m_pOnLineUpdateAct);
	m_pOperTlBar->addSeparator();
	m_pOperTlBar->addAction(m_pRefreshAct);
	m_pOperTlBar->addSeparator();
	m_pOperTlBar->addAction(m_pHeadPageAct);
	m_pOperTlBar->addAction(m_pPrePageAct);
	m_pOperTlBar->addWidget(&m_PageNoComBox);
	m_pOperTlBar->addAction(m_pNextPageAct);
	m_pOperTlBar->addAction(m_pTailPageAct);
	m_pOperTlBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	m_pOperTlBar->setIconSize(QSize(18,18));
}

void MyMainWindow::createStatusBar()
{
	statusBar()->showMessage(QString::fromLocal8Bit("就绪"));

	QString Str;
	Str = QString::fromLocal8Bit("  【单数据源；");
	Str += QString::fromLocal8Bit("单网；");
	Str += QString::fromLocal8Bit("离线运行");
	Str += QString::fromLocal8Bit("】 ");
	m_CurDsnInfoStr.setText(Str);
	m_CurDsnInfoStr.setAlignment(Qt::AlignLeft|Qt::AlignVCenter);//文字对齐方式为中间对齐
	m_CurDsnInfoStr.setMinimumSize(m_CurDsnInfoStr.sizeHint());


	m_CurTableName.setText(QString::fromLocal8Bit("  【当前选择：无】 "));
	m_CurTableName.setAlignment(Qt::AlignLeft|Qt::AlignVCenter);//文字对齐方式为中间对齐
	m_CurTableName.setMinimumSize(m_CurTableName.sizeHint());
	statusBar()->addPermanentWidget(&m_CurTableName,0);

	statusBar()->addPermanentWidget(&m_CurDsnInfoStr,0);
	statusBar()->setStyleSheet(QString::fromLocal8Bit("QStatusBar::item{border:　0px}"));
}


void MyMainWindow::createCentralWidget()
{
	m_pCentralTab = new QTabWidget(this);
	m_pCentralView = new MyTableWidget(&m_TableData, m_pTree, m_pCentralTab);

	//connect(this, SIGNAL(AddNewRecordSignal()), m_pCentralView, SLOT(OnAppendRow()));
	m_pCentralTab->addTab(m_pCentralView, QString::fromLocal8Bit("主工作区") );
	
	setCentralWidget(m_pCentralTab);
}


void MyMainWindow::createDockWindows()
{
	setDockOptions(QMainWindow::ForceTabbedDocks);
	setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);

	QString text_temp;//=QString::fromLocal8Bit("NSA3100HF配网");
	//m_pLeftTreeDock = new QDockWidget(text_temp, this, Qt::SubWindow);
	m_pLeftTreeDock = new QDockWidget(this,Qt::SubWindow|Qt::FramelessWindowHint|Qt::WindowCloseButtonHint);
	m_pLeftTreeDock->setAllowedAreas(Qt::LeftDockWidgetArea);
	QWidget *ltitle = new QWidget(m_pLeftTreeDock);
	m_pLeftTreeDock->setTitleBarWidget(ltitle);
	m_pLeftTreeDock->setFeatures( QDockWidget::NoDockWidgetFeatures);

	m_pTabWdgt = new QTabWidget(m_pLeftTreeDock);
	m_pLeftTreeDock->setWidget(m_pTabWdgt);
	m_pTabWdgt->setTabPosition(QTabWidget::North);

	m_pTreeWdgt = new MyTreeWidget(m_pTabWdgt);
	m_pTabWdgt->insertTab(0,m_pTreeWdgt,QString::fromLocal8Bit("导航"));
	m_pTabWdgt->setCurrentIndex(0);
	
	if (m_pTreeWdgt)
	{
		m_pTreeWdgt->InitTableTreeItem();
		connect(m_pTreeWdgt, SIGNAL(ShowTable_Signal(QTreeWidgetItem*)), this,SLOT(OnShowTableData(QTreeWidgetItem*)));
		connect(m_pTreeWdgt, SIGNAL(PopMenu_Signal(QPoint)), this, SLOT(upDateMenu(QPoint)));
		connect(this, SIGNAL(UpDateTreeItem_Signal(quint32, quint32, quint32, quint32,int)), m_pTreeWdgt, SLOT(OnUpDateTreeItem(quint32, quint32, quint32, quint32,int)));
	}

	m_pBottomTextDock = new QDockWidget(this);
	m_pBottomTextDock->setAllowedAreas(Qt::BottomDockWidgetArea);
	QWidget *btitle = new QWidget(m_pBottomTextDock);
	m_pBottomTextDock->setTitleBarWidget(btitle);
	m_pBottomTextDock->setFloating(false);
	
	m_pBottomTextDock->setFeatures( QDockWidget::NoDockWidgetFeatures);
	m_pBottomTextDock->setAllowedAreas(Qt::BottomDockWidgetArea);
	//m_pTextEdit = new QListWidget(m_pBottomTextDock);
	//m_pTextEdit = new TextView(QString::fromLocal8Bit("Ws_DB_Cfg"),m_pBottomTextDock);

	QTabWidget *m_pBottomTab = new QTabWidget(m_pBottomTextDock);
	m_pBottomTextDock->setWidget(m_pBottomTab);
	m_pBottomTab->setTabPosition(QTabWidget::North);

	m_pTextEdit = new QListWidget(m_pBottomTab);
	m_pBottomTab->insertTab(0, m_pTextEdit, QString::fromLocal8Bit("操作信息"));
	m_pBottomTextDock->setWidget(m_pBottomTab);

	m_pRightDock = new QDockWidget(this);
	m_pRightDock->setAllowedAreas(Qt::RightDockWidgetArea);
	m_pRightDock->setFeatures( QDockWidget::NoDockWidgetFeatures);
	QWidget *rtitle = new QWidget(m_pRightDock);
	m_pRightDock->setTitleBarWidget(rtitle);
	QTabWidget *m_pRightTab = new QTabWidget(m_pRightDock);
	m_pRightDock->setWidget(m_pRightTab);
	m_pRightTab->setTabPosition(QTabWidget::North);

	m_pPropView = new PropertyView(&m_TableData,m_pRightTab);
	m_pRightTab->addTab(m_pPropView,QString::fromLocal8Bit("属性"));
	//connect(this, SIGNAL(AddNewRecordSignal()), m_pPropView, SLOT(OnAppendRow()));

	addDockWidget(Qt::BottomDockWidgetArea, m_pBottomTextDock);
	addDockWidget(Qt::LeftDockWidgetArea, m_pLeftTreeDock);
	addDockWidget(Qt::RightDockWidgetArea, m_pRightDock);
}


void MyMainWindow::ConnectFunction()
{
	connect(m_pSaveDataAct, SIGNAL(triggered()), this, SLOT(SaveData()));
	if (m_pTreeWdgt)
	{
		connect(this, SIGNAL(UpTreeItem_Signal(QTreeWidgetItem*)), m_pTreeWdgt, SLOT(OnUpTreeItem_byItem(QTreeWidgetItem*)));
	}

	if (m_pCentralView)
	{		
// 		if (m_pAct_Save)
// 		{
// 			connect(m_pAct_Save, SIGNAL(triggered()), m_pCentralView, SLOT(OnSaveData()));
// 		}
		if (m_pPropView)
		{
			connect(m_pCentralView, SIGNAL(ClickRow_Signal(int)),          m_pPropView,    SLOT(OnShowRecord(int)));
			connect(m_pPropView,    SIGNAL(Signal_UserDataChang(int,int)), m_pCentralView, SLOT(OnSynicUserDataChang(int,int)));
			connect(m_pCentralView, SIGNAL(Signal_UserDataChang(int,int)), m_pPropView,    SLOT(OneFieldDataShow(int,int)));
			connect(m_pPropView, SIGNAL(Signal_ReInit()), m_pCentralView, SLOT(OnRefreshData()));
		}
//		connect(m_pSaveDataAct, SIGNAL(triggered()), m_pCentralView, SLOT(OnSaveData()));
		connect(m_pSetColAct, SIGNAL(triggered()), m_pCentralView, SLOT(OnSetColValue()));
		connect(m_pCentralView, SIGNAL(SelectItem_Signal(int, int ,int)), this, SLOT(SelectItem_slot(int, int ,int)));
		connect(this, SIGNAL(AddNewRecordSignal()), m_pCentralView, SLOT(OnAppendRow()));
		connect(m_pDelAct, SIGNAL(triggered()), m_pCentralView, SLOT(OnDeleteData()));
		connect(m_pCentralView, SIGNAL(SelectRow_Signal(int)), this, SLOT(SelectRow_slot(int)));
		connect(m_pCentralView, SIGNAL(SaveData_Signal(bool)), this, SLOT(NeedSave_Slot(bool)));
		connect(m_pSaveModelAct, SIGNAL(triggered()), m_pCentralView, SLOT(SaveDeviceToModel()));
		connect(m_pSaveModelFileAct, SIGNAL(triggered()), m_pCentralView, SLOT(SaveDevModelToFile()));
		connect(this, SIGNAL(ChangePage_Signal(int, int)),m_pCentralView, SLOT(OnPageShow(int,int)));
		connect(m_pCentralView, SIGNAL(PageNum_Signal(int)), this, SLOT(SetPageComboBoxNum(int)));
		connect(m_pCentralView, SIGNAL(PageCurNo_Signal(int)), this, SLOT(SetPageComboBoxCurNo(int)));
		connect(this, SIGNAL(RefreshDataShow_Signal()), m_pCentralView, SLOT(OnRefreshData()));
	}
		

}
//建立右键菜单
void MyMainWindow::setupPopMenuBar()
{
	m_PopMenu = new QMenu("PopMenu",this);
	QAction *action_S1= m_PopMenu->addAction(QString::fromLocal8Bit("增加"));
	connect(action_S1, SIGNAL(triggered()), this, SLOT(OnAddNewRecord()));
	action_S1->setData(ADD_MENU);
	m_PopMenu->addSeparator();

	
	/*QAction *action_S11= m_PopMenu->addAction(QString::fromLocal8Bit("更新ICD模型"));
	connect(action_S11, SIGNAL(triggered()), this, SLOT(OnUpdate61850ICDFile()));
	action_S11->setData(ADD_61850_DEVICE);
	m_PopMenu->addSeparator();*/

	QAction *action_S11 = m_PopMenu->addAction(QString::fromLocal8Bit("生成大排行号"));
	connect(action_S11, SIGNAL(triggered()), this, SLOT(OnGenerateTotalSort()));
	action_S11->setData(CREATE_61850_MAPFILE_MENU);
	m_PopMenu->addSeparator();

	QAction *action_S12 = m_PopMenu->addAction(QString::fromLocal8Bit("生成XML文件"));
	connect(action_S12, SIGNAL(triggered()), this, SLOT(OnCreateXmlFile()));
	action_S12->setData(CREATE_61850_MAPFILE_MENU);
	m_PopMenu->addSeparator();

	QAction *action_S2 = m_PopMenu->addAction(QString::fromLocal8Bit("遥信转发表"));
	connect(action_S2, SIGNAL(triggered()), this, SLOT(OnAddTransInfo()));

	action_S2->setData(YXTRANS_MENU);
	m_PopMenu->addSeparator();
	QAction *action_S3 = m_PopMenu->addAction(QString::fromLocal8Bit("遥测转发表"));
	connect(action_S3, SIGNAL(triggered()), this, SLOT(OnAddTransInfo()));
	action_S3->setData(YCTRANS_MENU);
	m_PopMenu->addSeparator();
	QAction *action_S4 = m_PopMenu->addAction(QString::fromLocal8Bit("遥控转发表"));
	connect(action_S4, SIGNAL(triggered()), this, SLOT(OnAddTransInfo()));
	action_S4->setData(YKTRANS_MENU);
	m_PopMenu->addSeparator();
	QAction *action_S5 = m_PopMenu->addAction(QString::fromLocal8Bit("遥脉转发表"));
	connect(action_S5, SIGNAL(triggered()), this, SLOT(OnAddTransInfo()));
	action_S5->setData(YMTRANS_MENU);
	m_PopMenu->addSeparator();

	QAction *action_S7 = m_PopMenu->addAction(QString::fromLocal8Bit("导出终端参数库"));
	connect(action_S7, SIGNAL(triggered()), this, SLOT(OnExportParamDB()));
	action_S7->setData(EXPORT_PARAMDB_MENU);
	m_PopMenu->addSeparator();
	
}

//ccg:由signal:PopMenu_Signal(QPoint)调用，根据光标所在树形列表位置，判断右击菜单是否enable
void MyMainWindow::upDateMenu(QPoint point)
{
	if ( (m_CurTreeItemData.AppType<=0 || m_CurTreeItemData.ShowTableId<=0 ) && m_CurTreeItemData.itemtype<=0)
	{
		return ;
	}
	if(m_PopMenu==NULL)
	{
		return;
	}
	m_PopMenu->popup(point);
	int index =0;
	int Menu_Count =0;
	int i=0;
	QAction * p_action = NULL;
	int data_menu=0;
	bool ok =false;
	bool	menuenable=false;
	index=0;
	menuenable = false;
	Menu_Count=0;

	m_PopAction_list =  m_PopMenu->actions();
	Menu_Count=m_PopAction_list.size();
	if(Menu_Count<=0)return;
	for(i=0;i<Menu_Count;i++)
	{
		p_action=m_PopAction_list.at(i);
		data_menu = p_action->data().toInt(&ok);//ccg如果转换失败ok会返回false；
		if(ok == false)continue;
		switch(data_menu)
		{
		case ADD_MENU://ccg在MyMainWindow::setupPopMenuBar()里setdata时设定。
			{
				if (IsCurTableEnableEdit(m_CurTreeItemData.AppType, m_CurTreeItemData.ShowTableId, m_CurTreeItemData.parentId))
				{
					if (/*m_CurTreeItemData.ShowTableId == TABLE_RSETPARA_INDEX ||*/
						m_CurTreeItemData.ShowTableId == TABLE_RTASK_PARA_INFO)
					{
						menuenable = false;
					}
					else if ( m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YX ||
							  m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YC ||
							  m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YM ||
							  m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YK)
					{
						menuenable = false;
					}else if (m_CurTreeItemData.ShowTableId==TABLE_RDATA_OBJECT)//ccg 取消逻辑节点右击增加键激活状态
				    {	
						menuenable = false;
					}
					else
					{
						menuenable = true;
					}
				}
				
				else
				{
					menuenable = false;
				}
			}
			break;
		case CREATE_61850_MAPFILE_MENU:
			{	
                 menuenable = true;		 
			}
			break;
		/*case ADD_61850_DEVICE:		//ccg增加61850设备激活
			{	
				if (m_CurTreeItemData.itemtype == NSA3100E_USER_TYPE_61850_MODEL)
				{
					menuenable = true;	
				}
				else
				{
					menuenable = false;
				}
					 
			}
			break;*/
		case YXTRANS_MENU:
			{
				if (m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YX)
				{
					menuenable = true;
				}else
				{
					menuenable = false;
				}
			}
			break;
		case YCTRANS_MENU:
			{
				if(m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YC)
				{
					menuenable = true;
				}else
				{
					menuenable = false;
				}
			}
			break;
		case YKTRANS_MENU:
			{
				if(m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YK)
				{
					menuenable = true;
				}else
				{
					menuenable = false;
				}
			}
			break;
		case YMTRANS_MENU:
			{
				if (m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YM) 
				{
					menuenable = true;
				}else
				{
					menuenable = false;
				}
			}
			break;
		case CREATETRANSTXT_MENU:
			{
				if (m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YX ||
					m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YC ||
					m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YK ||
					m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YM )
				{
					menuenable = true;
				}else
				{
					menuenable = false;
				}
			}
			break;
		
		case EXPORT_PARAMDB_MENU:
			{
				if (NSA3100E_USER_TYPE_SYS_PARAM == m_CurTreeItemData.itemtype)
				{
					menuenable = true;	
				}else
				{
					menuenable = false;
				}
			}
			break;
		default:
			menuenable = false;
			break;
		}
		p_action->setEnabled(menuenable);
	}
}

void MyMainWindow::UserLogin()
{
	/*LoginDialog pUserLogin;

	pUserLogin.exec();*/
}


void MyMainWindow::FreshTree()
{
	m_pTreeWdgt->InitTableTreeItem();
}

void MyMainWindow::DeleteData()
{

}

void MyMainWindow::SaveData()
{
	if (m_TableData.IsNewDataUnSaved())
	{
		m_TableData.bSaveData();
		emit RefreshDataShow_Signal();
		emit UpTreeItem_Signal(m_pLastSeltTreeItem);
		
	}
}

void MyMainWindow::RefreshData()
{
	emit RefreshDataShow_Signal();
}

void MyMainWindow::ShowTreeDock()
{
	if (!m_pLeftTreeDock)
		return;
	ShowDockWindow(m_pLeftTreeDock);
}

void MyMainWindow::ShowTextDock()
{
	if (!m_pBottomTextDock)
		return;
	ShowDockWindow(m_pBottomTextDock);
}

void MyMainWindow::ShowPropertyDock()
{
	if (!m_pRightDock)
		return;
	ShowDockWindow(m_pRightDock);
}

void MyMainWindow::ShowDockWindow(QDockWidget *pDockWidget)
{
	if (pDockWidget)
	{
		if (pDockWidget->isHidden())
		{
			pDockWidget->showNormal();
		}else
		{
			pDockWidget->hide();
		}
	}
}

void MyMainWindow::SelectRow_slot(int RowNum)    
{
	if (RowNum>0)
	{
		if (!m_pDelAct->isEnabled())
		{
			if (m_CurTreeItemData.AppType == SYSTEM_TYPE_NSA_YD && (/*m_CurTreeItemData.ShowTableId == TABLE_RSYS_INFO ||*/ m_CurTreeItemData.ShowTableId == TABLE_RTASK_PARA_INFO))
			{
				m_pDelAct->setEnabled(false);
			}
			else if ( m_CurTreeItemData.AppType == SYSTEM_TYPE_NSA_YD && 
				( m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YX ||
				  m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YC ||
				  m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YM ||
				  m_CurTreeItemData.ShowTableId == TABLE_RTRANSMIT_YK) )
			{
				m_pDelAct->setEnabled(false);
			}
			else
			{
				m_pDelAct->setEnabled(true);
			}
		}

	}else
	{
		if (m_pDelAct->isEnabled())
		{
			m_pDelAct->setEnabled(false);
		}
	}

	if (RowNum == 1 && m_CurTreeItemData.AppType == SYSTEM_TYPE_NSA_YD && m_CurTreeItemData.ShowTableId == TABLE_RDEVS_INFO)
	{
		if (!m_pSaveModelAct->isEnabled())
		{
			m_pSaveModelAct->setEnabled(true);
		}

	}else
	{
		if (m_pSaveModelAct->isEnabled())
		{
			m_pSaveModelAct->setEnabled(false);
		}
	}
	if (RowNum == 1 && m_CurTreeItemData.AppType == SYSTEM_TYPE_NSA_YD && m_CurTreeItemData.ShowTableId == TABLE_RDEVMODEL_INFO)
	{
		if (!m_pSaveModelFileAct->isEnabled())
		{
			m_pSaveModelFileAct->setEnabled(true);
		}

	}else
	{
		if (m_pSaveModelFileAct->isEnabled())
		{
			m_pSaveModelFileAct->setEnabled(false);
		}
	}
}


void MyMainWindow::SelectItem_slot(int ItemRowNum, int ItemColNum, int ItemColIndex)
{
	if (ItemRowNum>1 && ItemColNum==1)
	{
		if (!m_pSetColAct->isEnabled())
		{
			if (ItemColIndex==1)
			{
				m_pSetColAct->setEnabled(false);
			}
			else
			{
				m_pSetColAct->setEnabled(true);
			}
		}
		else
		{
			if (ItemColIndex==1)
			{
				m_pSetColAct->setEnabled(false);
			}
			else
			{
				m_pSetColAct->setEnabled(true);
			}
		}
	}else
	{
		if (m_pSetColAct->isEnabled())
		{
			m_pSetColAct->setEnabled(false);
		}
	}
}

void MyMainWindow::NeedSave_Slot(bool bSave)
{
	if (m_pSaveDataAct->isEnabled() && !bSave)
	{
		m_pSaveDataAct->setEnabled(false);
	}
	if (!m_pSaveDataAct->isEnabled() && bSave)
	{
		m_pSaveDataAct->setEnabled(true);
	}
}

void MyMainWindow::ShowTableView(int AppType, int TableId, int ParentId, QTreeWidgetItem *pCurTreeItem,int PtlParamType)
{
// 	m_pMdiArea->closeActiveSubWindow();
// 	if (!m_pMdiArea->activeSubWindow())
// 	{
// 		MyTableWidget *pMyTableWidget = new MyTableWidget(m_pTreeWdgt);
// 		connect(m_pSaveDataAct, SIGNAL(triggered()), pMyTableWidget, SLOT(OnSaveData()));
// 		connect(this, SIGNAL(RefreshDataShow_Signal()), pMyTableWidget, SLOT(OnRefreshData()));
// 
// 		if (PtlParamType>0)
// 		{
// 			disconnect(m_pSetColAct, SIGNAL(triggered()), pMyTableWidget, SLOT(OnSetColValue()));
// 			disconnect(pMyTableWidget, SIGNAL(SelectItem_Signal(int, int ,int)), this, SLOT(SelectItem_slot(int, int ,int)));
// 			disconnect(this, SIGNAL(AddNewRecordSignal()), pMyTableWidget, SLOT(OnAppendRow()));
// 			disconnect(m_pDelAct, SIGNAL(triggered()), pMyTableWidget, SLOT(OnDeleteData()));
// 			disconnect(pMyTableWidget, SIGNAL(SelectRow_Signal(int)), this, SLOT(SelectRow_slot(int)));
// 			connect(pMyTableWidget, SIGNAL(SaveData_Signal(bool)), this, SLOT(NeedSave_Slot(bool)));
// 			disconnect(m_pSaveModelAct, SIGNAL(triggered()), pMyTableWidget, SLOT(SaveDeviceToModel()));
// 			disconnect(m_pSaveModelFileAct, SIGNAL(triggered()), pMyTableWidget, SLOT(SaveDevModelToFile()));
// 			//disconnect(pMyTableWidget, SIGNAL(CheckOnline_Signal()), this, SLOT(NeedOnLineUpDate_Slot()));
// 			disconnect(this, SIGNAL(ChangePage_Signal(int, int)),pMyTableWidget, SLOT(OnPageShow(int,int)));
// 			disconnect(pMyTableWidget, SIGNAL(PageNum_Signal(int)), this, SLOT(SetPageComboBoxNum(int)));
// 			disconnect(pMyTableWidget, SIGNAL(PageCurNo_Signal(int)), this, SLOT(SetPageComboBoxCurNo(int)));
// 		}
// 		else
// 		{
// 			connect(m_pSetColAct, SIGNAL(triggered()), pMyTableWidget, SLOT(OnSetColValue()));
// 			connect(pMyTableWidget, SIGNAL(SelectItem_Signal(int, int ,int)), this, SLOT(SelectItem_slot(int, int ,int)));
// 			connect(this, SIGNAL(AddNewRecordSignal()), pMyTableWidget, SLOT(OnAppendRow()));
// 			connect(m_pDelAct, SIGNAL(triggered()), pMyTableWidget, SLOT(OnDeleteData()));
// 			connect(pMyTableWidget, SIGNAL(SelectRow_Signal(int)), this, SLOT(SelectRow_slot(int)));
// 			connect(pMyTableWidget, SIGNAL(SaveData_Signal(bool)), this, SLOT(NeedSave_Slot(bool)));
// 			connect(m_pSaveModelAct, SIGNAL(triggered()), pMyTableWidget, SLOT(SaveDeviceToModel()));
// 			connect(m_pSaveModelFileAct, SIGNAL(triggered()), pMyTableWidget, SLOT(SaveDevModelToFile()));
// 			//connect(pMyTableWidget, SIGNAL(CheckOnline_Signal()), this, SLOT(NeedOnLineUpDate_Slot()));
// 			connect(this, SIGNAL(ChangePage_Signal(int, int)),pMyTableWidget, SLOT(OnPageShow(int,int)));
// 			connect(pMyTableWidget, SIGNAL(PageNum_Signal(int)), this, SLOT(SetPageComboBoxNum(int)));
// 			connect(pMyTableWidget, SIGNAL(PageCurNo_Signal(int)), this, SLOT(SetPageComboBoxCurNo(int)));
// 		}
// 
// 		setCursor(QCursor(Qt::WaitCursor));
// 		m_pMdiArea->addSubWindow(pMyTableWidget);
// 		pMyTableWidget->repaint();
// 
// 		if (IsCurTableEnableEdit(AppType, TableId, ParentId) &&
// 			(TABLE_RTRANSMIT_YX != TableId && 
// 			TABLE_RTRANSMIT_YC != TableId &&
// 			TABLE_RTRANSMIT_YK != TableId &&
// 			TABLE_RTRANSMIT_YM != TableId &&
// 			/*TABLE_RSYS_INFO != TableId  &&*/
// 			TABLE_RTASK_PARA_INFO != TableId ) )
// 		{
// 			if (!m_pAddAct->isEnabled())
// 			{
// 				m_pAddAct->setEnabled(true);
// 			}
// 		}
// 		pMyTableWidget->InitCurTreeItemDataShow(pCurTreeItem,PtlParamType);
// 		pMyTableWidget->showMaximized();
// 		setCursor(QCursor(Qt::ArrowCursor));
// 		if (!m_pTreeWdgt->hasFocus())
// 		{
// 			m_pTreeWdgt->setFocus();
// 		}
// 	}else
// 	{
// 		if (PtlParamType>0)
// 		{
// 			disconnect(m_pSetColAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnSetColValue()));
// 			disconnect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(SelectItem_Signal(int, int ,int)), this, SLOT(SelectItem_slot(int, int ,int)));
// 			disconnect(this, SIGNAL(AddNewRecordSignal()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnAppendRow()));
// 			disconnect(m_pDelAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnDeleteData()));
// 			disconnect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(SelectRow_Signal(int)), this, SLOT(SelectRow_slot(int)));
// 			connect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(SaveData_Signal(bool)), this, SLOT(NeedSave_Slot(bool)));
// 			disconnect(m_pSaveModelAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(SaveDeviceToModel()));
// 			disconnect(m_pSaveModelFileAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(SaveDevModelToFile()));
// 			//disconnect(pMyTableWidget, SIGNAL(CheckOnline_Signal()), this, SLOT(NeedOnLineUpDate_Slot()));
// 			disconnect(this, SIGNAL(ChangePage_Signal(int, int)),((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnPageShow(int,int)));
// 			disconnect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(PageNum_Signal(int)), this, SLOT(SetPageComboBoxNum(int)));
// 			disconnect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(PageCurNo_Signal(int)), this, SLOT(SetPageComboBoxCurNo(int)));
// 		}
// 		else
// 		{
// 			connect(m_pSetColAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnSetColValue()));
// 			connect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(SelectItem_Signal(int, int ,int)), this, SLOT(SelectItem_slot(int, int ,int)));
// 			connect(this, SIGNAL(AddNewRecordSignal()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnAppendRow()));
// 			connect(m_pDelAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnDeleteData()));
// 			connect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(SelectRow_Signal(int)), this, SLOT(SelectRow_slot(int)));
// 			connect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(SaveData_Signal(bool)), this, SLOT(NeedSave_Slot(bool)));
// 			connect(m_pSaveModelAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(SaveDeviceToModel()));
// 			connect(m_pSaveModelFileAct, SIGNAL(triggered()), ((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(SaveDevModelToFile()));
// 			//connect(pMyTableWidget, SIGNAL(CheckOnline_Signal()), this, SLOT(NeedOnLineUpDate_Slot()));
// 			connect(this, SIGNAL(ChangePage_Signal(int, int)),((MyTableWidget *)m_pMdiArea->activeSubWindow()), SLOT(OnPageShow(int,int)));
// 			connect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(PageNum_Signal(int)), this, SLOT(SetPageComboBoxNum(int)));
// 			connect(((MyTableWidget *)m_pMdiArea->activeSubWindow()), SIGNAL(PageCurNo_Signal(int)), this, SLOT(SetPageComboBoxCurNo(int)));
// 		}
// 
// 		setCursor(QCursor(Qt::WaitCursor));
// 
// 		if (IsCurTableEnableEdit(AppType, TableId, ParentId) &&
// 			(TABLE_RTRANSMIT_YX != TableId && 
// 			TABLE_RTRANSMIT_YC != TableId &&
// 			TABLE_RTRANSMIT_YK != TableId &&
// 			TABLE_RTRANSMIT_YM != TableId  &&
// 		/*	TABLE_RSETPARA_INDEX != TableId  &&*/
// 			TABLE_RTASK_PARA_INFO != TableId  ) )
// 		{
// 			if (!m_pAddAct->isEnabled())
// 			{
// 				m_pAddAct->setEnabled(true);
// 			}
// 		}
// 		((MyTableWidget *)m_pMdiArea->activeSubWindow())->InitCurTreeItemDataShow(pCurTreeItem,PtlParamType);
// 		m_pMdiArea->activeSubWindow()->showMaximized();
// 		setCursor(QCursor(Qt::ArrowCursor));
// 		//qDebug()<<QString::fromLocal8Bit("激活窗口\r\n");
// 		if (!m_pTreeWdgt->hasFocus())
// 		{
// 			m_pTreeWdgt->setFocus();
// 		}
// 	}
}



//响应点击树ITEM信号
void MyMainWindow::OnShowTableData(QTreeWidgetItem *pCurTreeItem)
{
	if (pCurTreeItem)
	{

		int Ret = 0;
		if (m_pLastSeltTreeItem != pCurTreeItem && m_pLastSeltTreeItem)
		{
			/*Ret =*/ CheckNeedSaveOpe();
			//if (2 == Ret)
			//{
			//	emit ReShowTable_Signal(m_pLastSeltTreeItem);
			//	return ;
			//}
		}

		TreeItemData NewData ;
		NewData = pCurTreeItem->data(0, Qt::UserRole).value<TreeItemData>();
		//ccg增加一个全局变量，记录点击树item显示的名称，给右击61850设备用
		m_CurTreeItemName = pCurTreeItem->text(0);
		m_CurTreeItemData = NewData;
		if (NewData.AppType>0 && NewData.ShowTableId>0 /*&& NewData.ShowTableId!=TABLE_RLOGIC_DEVICE*/)
		{
			m_TableData.InitTableData(NewData.AppType, NewData.ShowTableId, NewData.parentId, NewData.RecordId, NewData.PtlParamType,NewData.Fun);
			if (m_pCentralView)
			{
				m_pCentralView->InitCurTreeItemDataShow(pCurTreeItem,NewData.PtlParamType);
			}
			if (m_pPropView)
			{
				m_pPropView->InitPropertyTitle(); 
			}
			if (m_pCentralTab)
			{
				if (m_pCentralTab->count()>0)
				{
					QString TabTitleStr;
					TabTitleStr = pCurTreeItem->text(0);
					if (TABLE_RTASK_PARA_INFO == NewData.ShowTableId)
					{
						TabTitleStr += QString::fromLocal8Bit("->规约参数");
					}
					m_pCentralTab->setTabText(0, TabTitleStr);
					m_pCentralTab->tabText(0);
				}
			}
			SetEditState();
		}else
		{
			if (NSA3100E_USER_TYPE_SYS_PARAM == NewData.itemtype)
			{
				if (!m_pSaveModelAct->isEnabled())
					m_pSaveModelAct->setEnabled(true);
			}
		
			else
			{
				if (m_pSaveModelAct->isEnabled())
					m_pSaveModelAct->setEnabled(false);
			}
			m_pCentralTab->setTabText(0, QString::fromLocal8Bit("主工作区"));
			m_pCentralView->ClearAllShowCont();
			m_pPropView->ClearAllShowCont();
		}
		m_pLastSeltTreeItem = pCurTreeItem;
		//TreeItemData NewData ;
		NewData = m_pLastSeltTreeItem->data(0, Qt::UserRole).value<TreeItemData>();
	}
}
void MyMainWindow::SetEditState()
{
	if (!m_pRefreshAct->isEnabled())
	{
		m_pRefreshAct->setEnabled(true);
	}
	if (m_pDelAct->isEnabled())
	{
		m_pDelAct->setEnabled(false);
	}
	if (m_pSaveDataAct->isEnabled())
	{
		m_pSaveDataAct->setEnabled(false);
	}
	if (!m_pAddAct->isEnabled())
	{
		m_pAddAct->setEnabled(true);
	}

	if (m_pSaveModelAct->isEnabled())
	{
		m_pSaveModelAct->setEnabled(false);
	}
	if (m_pSaveModelFileAct->isEnabled())
	{
		m_pSaveModelFileAct->setEnabled(false);
	}
}
/*
void MyMainWindow::ShowTableData(QTreeWidgetItem *pCurTreeItem)
{
	if (m_pMdiArea->activeSubWindow())
	{
		m_pMdiArea->activeSubWindow()->close();
	}

	if (pCurTreeItem)
	{
		TreeItemData NewData ;
		QString		StrTableName;
		NewData = pCurTreeItem->data(0, Qt::UserRole).value<TreeItemData>();

		m_pTreeWdgt->CurData = NewData;
		m_CurTreeItemData = NewData;
		if (m_pDelAct->isEnabled())
		{
			m_pDelAct->setEnabled(false);
		}
		if (m_pSaveDataAct->isEnabled())
		{
			m_pSaveDataAct->setEnabled(false);
		}
		if (m_pAddAct->isEnabled())
		{
			m_pAddAct->setEnabled(false);
		}

//		if (m_pSaveModelAct->isEnabled())
//		{
//			m_pSaveModelAct->setEnabled(false);
//		}

//		if (m_pSaveModelFileAct->isEnabled())
//		{
//			m_pSaveModelFileAct->setEnabled(false);
//		}

		if (NewData.AppType>0 && NewData.ShowTableId>0)
		{
			if (!m_pRefreshAct->isEnabled())
			{
				m_pRefreshAct->setEnabled(true);
			}
			if (g_DbCfgFunObj.GetTableChnNamebyAppType_TableId(NewData.AppType, NewData.ShowTableId, StrTableName)<=0)
			{
				StrTableName = QString("获取表名错误AppType=%1,TableId=%2").arg(NewData.AppType).arg(NewData.ShowTableId);
			}
			m_CurTableName.setText(QString::fromLocal8Bit("  【当前选择：%1】 ").arg(StrTableName));
			//statusBar()->addPermanentWidget(&m_CurTableName);
			ShowTableView(NewData.AppType, NewData.ShowTableId, NewData.parentId, pCurTreeItem,NewData.PtlParamType);
		}else
		{
			if (m_pRefreshAct->isEnabled())
			{
				m_pRefreshAct->setEnabled(false);
			}
			m_CurTableName.setText(QString::fromLocal8Bit("  【当前选择：无】 "));
		}
	}
}
*/

void MyMainWindow::OnExportParamDB()
{
	if (NSA3100E_USER_TYPE_SYS_PARAM == m_CurTreeItemData.itemtype)
	{
		ExportParamDbdlg exParamDlg;
		exParamDlg.exec();
	}
}

void MyMainWindow::OnCreateXmlFile()
{
	ExportXmlDlg dlg(this);
	dlg.exec();
}
void MyMainWindow::OnGenerateTotalSort()
{
	GenerateTotalSort dlg(this);
	dlg.exec();
}

//槽函数，添加61850设备ccg
/*
void MyMainWindow::OnUpdate61850ICDFile()
{
	QString fileName = QFileDialog::getOpenFileName(this, tr("open file"), " ",  tr("Allfile(*.*);;icdfile(*.icd)"));
	//读打开的icd文件；
	if (!fileName.isEmpty())
	{
		m_pTreeWdgt->readIcdFile(fileName);
	}
	
}
*/

void MyMainWindow::OnAddNewRecord()
{
	if (SYSTEM_TYPE_NSA_YD == m_CurTreeItemData.AppType)
	{
		switch(m_CurTreeItemData.ShowTableId)
		{
		case TABLE_RDEVMODEL_INFO: //20
			{
				AddCommDevModel();
			}
			break;
		case TABLE_RDEVS_INFO:
			{
				if (m_CurTreeItemData.parentId>0)
				{
					AddDevice(m_CurTreeItemData.parentId);
				}
			}
			break;
		case TABLE_REXPDEFINE_INFO:
			{
				ExpEditDlg *pExpDlg = new ExpEditDlg(0);
				pExpDlg->exec();
				RefreshData();																	
			}
			break;
		case TABLE_RLOGIC_NODE: //CCG:61850模型逻辑设备右击添加
			{
				//select ID from rLogic_Device where Name = 'LD1':根据Name获取设备ID
				//没有现成的函数，直接操作SQL语句
				int TableInfo_Temp = 0;
				char	Sql[SQL_MAX_LEN];
				int	Result = 0;
				char	*buff = NULL;
				int	buff_len = 0;
				int LogicDeviceID = 0;
				memset(Sql, 0, SQL_MAX_LEN);
				sprintf(Sql, "select ID from rLogic_Device where Name='%s'", m_CurTreeItemName.toLocal8Bit().data());
				Result = g_pSqLiteDB.DB_SelectUInt(Sql,buff, &buff_len);
				//获取当前右击的逻辑设备的ID；
				if (Result>0 && buff && buff_len>0)
				{
					memcpy((char*)&TableInfo_Temp, buff, 4);
					LogicDeviceID = TableInfo_Temp;
					
				}
				LogicNodeDlg *lnDlg = new LogicNodeDlg(m_CurTreeItemName,LogicDeviceID,m_pTreeWdgt,0);
				lnDlg->exec();
				RefreshData();																	
			}
			break;
		/*case TABLE_RLOGIC_DEVICE://逻辑节点配置，增加触发的是打开文件读取icd文件功能 readIcdFile();
			{
				
					
				
					QString fileName = QFileDialog::getOpenFileName(this, tr("open icd file"), " ",  tr("Allfile(*.*);;icdfile(*.icd)"));
					//读打开的icd文件；
					if (!fileName.isEmpty())
					{
						QMessageBox::information(NULL, QString::fromLocal8Bit("温馨提示"), QString::fromLocal8Bit("即将从ICD文件读取模型信息，时间较长，请不要关闭窗口！"));

						m_pTreeWdgt->readIcdFile(fileName);
						QMessageBox::information(NULL, QString::fromLocal8Bit("Warn"), QString::fromLocal8Bit("读取完毕！"));
					}	
				

																				
			}
			break;*/
		default:
			{
				emit AddNewRecordSignal();
			} 
			break;
		}
	}

}

void MyMainWindow::AddSetParaIndex(unsigned int ParentId)
{
	;
}
//	添加设备
void MyMainWindow::AddDevice(unsigned int ParentId)
{
	if (ParentId<=0)
	{
		return ;
	}
	QMessageBox::StandardButton ret;
	ret = QMessageBox::question(this, QString::fromLocal8Bit("数据库组态"), QString::fromLocal8Bit("是否从模板添加？"), QMessageBox::Yes | QMessageBox::No);
	if (ret == QMessageBox::Yes)
	{
		DeviceDlg DevDlg(ParentId);
		connect(&DevDlg, SIGNAL(UpDateTreeItem_Signal(quint32, quint32, quint32, quint32,int)), m_pTreeWdgt, SLOT(OnUpDateTreeItem(quint32, quint32, quint32, quint32,int)));
		connect(&DevDlg, SIGNAL(RefreshData_Signal()), this, SLOT(RefreshData()));

		DevDlg.exec();
	}else if (ret == QMessageBox::No)
	{
		emit AddNewRecordSignal();
	}
}


//  添加普通设备模板
void MyMainWindow::AddCommDevModel()
{
	InsertDevModeDlg dlg;
	connect(&dlg, SIGNAL(UpDateDevModeItem_Signal(quint32, quint32, quint32, quint32,int)),  m_pTreeWdgt, SLOT(OnUpDateTreeItem(quint32, quint32, quint32, quint32,int)));
	connect(&dlg, SIGNAL(RefreshData_Signal()), this, SLOT(RefreshData()));
	dlg.exec();
}


//添加转发信息
void MyMainWindow::OnAddTransInfo()
{
	TransDlg dlg(m_CurTreeItemData.ShowTableId,m_CurTreeItemData.parentId, this);
	dlg.exec();
	RefreshData();
}


//生成转发对照表
void MyMainWindow::OnMakeTransInfo()
{
	/*int m_RoutId = 0;
	int m_TransInfoId = 0;
	// 	if (m_CurTreeItemData.parentId/PARENT_OFFSET == ID_TABLE_FRONTROUT_TABLE)
	// 	{
	// 		m_RoutId = m_pID%SYSTEM_MAX_NUM;
	// 		m_TransInfoId = m_TableData.GetTransInfoIdByRoutID(m_RoutId);
	// 	}else 
	if (m_CurTreeItemData.parentId/PARENT_OFFSET == TABLE_RTRANSMIT_PARAM_INFO)
	{
		m_TransInfoId = m_CurTreeItemData.parentId%PARENT_OFFSET;
	}
	if (m_TransInfoId>0)
	{
		g_DbCfgFunObj.MakeTransInfoToFile(m_TransInfoId);
	}*/

}

//移动到第一页
void MyMainWindow::OnHeadPage()
{
	emit ChangePage_Signal(PAGE_ACT_TYPE_MOVE_HEAD,0);
}
//移动到第一页
void MyMainWindow::OnPrevPage()
{
	emit ChangePage_Signal(PAGE_ACT_TYPE_MOVE_PREV,0);
}
//移动到第一页
void MyMainWindow::OnNextPage()
{
	emit ChangePage_Signal(PAGE_ACT_TYPE_MOVE_NEXT,0);
}
//移动到第一页
void MyMainWindow::OnTailPage()
{
	emit ChangePage_Signal(PAGE_ACT_TYPE_MOVE_TAIL,0);
}
//移动到第一页
void MyMainWindow::OnMoveToPage(int ItemIndex)
{
	if (ItemIndex>=0 && ItemIndex <m_PageNoComBox.maxCount() )
	{
		emit ChangePage_Signal(PAGE_ACT_TYPE_MOVE_ASSIGN,ItemIndex);
	}
}
void MyMainWindow::SetPageComboBoxNum(int PageNum)
{
	disconnect(&m_PageNoComBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnMoveToPage(int)));
	m_PageNoComBox.clear();
	if (PageNum>0)
	{
		QString ItemText;
		for (int i=1;i<=PageNum; i++)
		{
			ItemText = QString::fromLocal8Bit("%1/%2").arg(i).arg      (PageNum);
			m_PageNoComBox.insertItem(i,ItemText);
		}
		m_PageNoComBox.setCurrentIndex(0);
		SetPageActShowState(0, PageNum);
	}
	connect(&m_PageNoComBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnMoveToPage(int)));
}

void MyMainWindow::SetPageComboBoxCurNo(int PageNo)
{
	disconnect(&m_PageNoComBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnMoveToPage(int)));
	int PageCount = m_PageNoComBox.count();
	if (PageNo>=0 && PageNo<PageCount)
	{
		m_PageNoComBox.setCurrentIndex(PageNo);
		SetPageActShowState(PageNo, PageCount);
	}
	connect(&m_PageNoComBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnMoveToPage(int)));
}

void MyMainWindow::SetPageActShowState(int CurPageNo, int PageCount)
{
	if (CurPageNo< 0 || PageCount<0)
	{
		return ;
	}
	if (!m_pHeadPageAct ||
		!m_pNextPageAct ||
		!m_pPrePageAct ||
		!m_pTailPageAct)
	{
		return ;
	}
	if (0 == PageCount)
	{
		m_pHeadPageAct->setEnabled(false);	
		m_pPrePageAct->setEnabled(false);
		m_pNextPageAct->setEnabled(false);	
		m_pTailPageAct->setEnabled(false);
	}else
	{
		if (0 == CurPageNo)
		{
			m_pHeadPageAct->setEnabled(false);	
			m_pPrePageAct->setEnabled(false);
			if (PageCount>1)
			{
				if (!m_pTailPageAct->isEnabled())
				{
					m_pTailPageAct->setEnabled(true);
				}
				if (!m_pNextPageAct->isEnabled())
				{
					m_pNextPageAct->setEnabled(true);
				}
			}
		}

		if (CurPageNo+1 >= PageCount)
		{
			m_pTailPageAct->setEnabled(false);
			m_pNextPageAct->setEnabled(false);
			if (CurPageNo>0)
			{
				if (!m_pHeadPageAct->isEnabled())
				{
					m_pHeadPageAct->setEnabled(true);
				}
				if (!m_pPrePageAct->isEnabled())
				{
					m_pPrePageAct->setEnabled(true);
				}
			}
		}

		if (CurPageNo>0 && CurPageNo+1<PageCount)
		{
			if (!m_pHeadPageAct->isEnabled())
			{
				m_pHeadPageAct->setEnabled(true);
			}
			if (!m_pPrePageAct->isEnabled())
			{
				m_pPrePageAct->setEnabled(true);
			}

			if (!m_pTailPageAct->isEnabled())
			{
				m_pTailPageAct->setEnabled(true);
			}
			if (!m_pNextPageAct->isEnabled())
			{
				m_pNextPageAct->setEnabled(true);
			}
		}
	}

}


int MyMainWindow::CheckNeedSaveOpe()
{
	int	Result = 0;
	if (m_TableData.IsNewDataUnSaved())
	{
		QMessageBox Msg(QMessageBox::Question, QString::fromLocal8Bit("保存数据"), QString::fromLocal8Bit("当前表已更改, 确认保存吗？"));
		QAbstractButton  *pYesBtn = (QAbstractButton  *)Msg.addButton(QString::fromLocal8Bit("是(&Y)"), QMessageBox::YesRole);
		QAbstractButton  *pNoBtn = (QAbstractButton  *)Msg.addButton(QString::fromLocal8Bit("否(&N)"), QMessageBox::NoRole);
		//QAbstractButton  *pCancelBtn = (QAbstractButton  *)Msg.addButton(QString::fromLocal8Bit("取消"), QMessageBox::RejectRole);
		Msg.exec();
		if (Msg.clickedButton() == pYesBtn)
		{
			if (m_TableData.bSaveData()<=0)
			{
				QMessageBox::information(this, QString::fromLocal8Bit("保存数据"), QString::fromLocal8Bit("保存失败\r\n"));
				//	return false;
			}
			Result = 1;
		}else if (Msg.clickedButton() == pNoBtn)
		{
			Result = 1;
		}
// 		else if (Msg.clickedButton() == pCancelBtn)
// 		{
// 			Result = 2;
// 		}
	}
	return Result;
}